//
//  XLComposeTextView.swift
//  XLVeibo
//
//  Created by macbook on 16/7/3.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit

class XLComposeTextView: UITextView {

    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //重写站位文字
    var placeolder:String?{
    
        didSet{
        
            label.text = placeolder
        }
    }

    
    //重写字体大小
    override var font: UIFont?{
    
        didSet{
        
            label.font = font
        }
    }
    
    
    func setupUI(){
    
        addSubview(label)
        
        label.snp_makeConstraints { (make) in
            
            make.top.equalTo(self).offset(8)
            make.left.equalTo(self).offset(5)
            make.right.equalTo(self).offset(-5)
            

            //通过系统通知监听文字变化
            NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(XLComposeTextView.textViewTextDidChang), name: UITextViewTextDidChangeNotification, object: nil)

        }
    }
    
    //移除通知
    deinit{
        
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }

    
    //监听值的变化
    func textViewTextDidChang(){
    
        label.hidden = hasText()
    }
    
    
    
    
    
    private lazy var label:UILabel = {
    
        let label = UILabel()
        label.text = "这就只是占位而已"
        label.font = UIFont.systemFontOfSize(12)
        label.numberOfLines = 0
        label.textColor = UIColor.grayColor()
        return label
        
    }()
    
}











